/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.exception;

/**
 * 系统异常，抛出系统异常，应该提供异常码及错误信息。
 * <p>
 * 示例：
 *
 * <pre>
 * throw new SystemException("E0001", "服务xxx调用异常");
 *
 * 前端呈现：请求处理失败[E0001]，请稍后再试！
 * 后台日志：[E0001]服务xxx调用异常 + StackTrace
 * </pre>
 * </p>
 *
 * @auther ebert_chan
 */
public class SystemException extends RuntimeException {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * 异常码
     */
    private String code;

    /**
     * 异常信息
     */
    private String message;

    // public constructors

    public SystemException(String code, String message) {
        this(code, message, null);
    }

    public SystemException(String code, String message, Throwable cause) {
        super(cause);
        this.code = code;
        this.message = message;
    }

    // getter and setter

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMessage() {
        return "[" + getCode() + "]" + message;
    }

}
